package com.quwan.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quwan.entity.TRechargeVip;
import com.quwan.manager.controller.dto.RechargeVipDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.time.LocalDate;


public interface TRechargeVipMapper extends BaseMapper<TRechargeVip> {

    @Select({"<script>",
            " select rv.id, rv.vip_id as vip_rule_id, rv.m_id, rv.recharge_slip_num, rv.money, rv.pay_method, rv.tips, rv.status, rv.transaction_id, rv.pre_pay_id, rv.pay_time, rv.add_time," +
                    " m.name, m.nick_name, m.mobile, m.nick_name,vr.unit  " +
                    " from ",
            " t_recharge_vip rv left join t_member m on rv.m_id=m.id left  join t_vip_rule vr on rv.vip_id = vr.id ",
            "  where rv.status = 1 ",
            " <if test='mId != null '>",
            " and rv.m_id = #{mId}",
            "</if>",
            " <if test='status != null '>",
            " and rv.status = #{status}",
            "</if>",
            " <if test='minDate != null '>",
            " and rv.add_time <![CDATA[ >= ]]> #{minDate}",
            "</if>",
            " <if test='maxDate != null '>",
            " and rv.add_time <![CDATA[ <= ]]> #{maxDate}",
            "</if>",
            " <if test='max != null '>",
            " and rv.money <![CDATA[ <= ]]> #{max}",
            "</if>",
            " <if test='min != null '>",
            " and rv.money <![CDATA[ >= ]]> #{min}",
            "</if>",
            " <if test='vipRuleId != null '>",
            " and rv.vip_id = #{vipRuleId}",
            "</if>",
            " <if test='payMethod != null '>",
            " and rv.pay_method = #{payMethod}",
            "</if>",
            " <if test='name != null '>",
            " and m.name like CONCAT('%',#{name},'%')",
            "</if>",
            " <if test='nikeName != null '>",
            " and m.nick_name like CONCAT('%',#{nikeName},'%')",
            "</if>",
            " <if test='mobile != null '>",
            " and m.mobile like CONCAT('%',#{mobile},'%')",
            "</if>",
            " order by rv.add_time desc",
            "</script>"})
    Page<RechargeVipDTO> selectRechargeVipList(Page page,
                                                     @Param("nikeName") String nikeName,
                                                     @Param("mobile") String mobile,
                                                     @Param("min") Long min,
                                                     @Param("max") Long max,
                                                     @Param("minDate") LocalDate minDate,
                                                     @Param("maxDate") LocalDate maxDate,
                                                     @Param("status") Integer status,
                                                     @Param("name") String name,
                                                     @Param("mId") Long mId,
                                                     @Param("vipRuleId") Integer vipRuleId,
                                                     @Param("payMethod") Integer payMethod);

}